﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Controls;

using Gonte.Wpf.Controls.ViewModel;

using MyWpfControlsTest.Model;

namespace MyWpfControlsTest.ViewModel
{
    public class RootTreeItemViewModel
        : ViewModelTemplate<RootTreeItem>
    {
        #region Read Only

        //internal readonly BitmapImage IconImage = new BitmapImage(new Uri(@"pack://application:,,/Images/Root.jpg"));

        #endregion

        public RootTreeItemViewModel()
            : base(new RootTreeItem(), null, false)
        {
            //IconSource = IconImage;
        }

        public ReadOnlyCollection<RootTreeItemViewModel> RootDemo
        {
            get
            {
                return new ReadOnlyCollection<RootTreeItemViewModel>
                (
                    new RootTreeItemViewModel[] { this }
                );
            }
        }

        public override bool AddChild(ViewModelBase viewModel)
        {
            ChildTreeItemViewModel childViewModel = (ChildTreeItemViewModel)viewModel;

            ConcreteModel.Children.Add(childViewModel.ConcreteModel);

            return base.AddChild(viewModel);
        }

        public override void LoadChildren()
        {
            foreach (ChildTreeItem item in ConcreteModel.Children)
            {
                ChildTreeItemViewModel childViewModel = new ChildTreeItemViewModel(item, this);
                base.AddChild(childViewModel);
            }

            base.LoadChildren();
        }

        public override void OnPropertyChanged(String propertyName, Object oldValue)
        {
            if (propertyName.Equals("Name"))
            {
                base.OnPropertyChanged("Label");
            }
        }

        public override String Label
        {
            get { return "Root Item"; }
            set { }
        }

        public override ContextMenu CreateContextMenu()
        {
            return new ContextMenu();
        }
    }
}
